package com.imooc.mall.common;

import com.google.common.collect.Sets;
import com.imooc.mall.exception.ImoocMallException;
import com.imooc.mall.exception.ImoocMallExceptionEnum;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Set;

@Component
public class Constant {

    public static final String SALT = "2113EWQE1313X.,]";

    public static final String IM00C_MALL_USER = "imooc_mall_user";

//    @Value("${file.upload.dir}")
     public static String FILE_UPLOAD_DIR;

     @Value("${file.upload.dir}")
    public void setFileDir(String FileUploadDir){
        FILE_UPLOAD_DIR = FileUploadDir;
    }

    public interface ProductListOrderBy{
         Set<String> PRICE_ASC_DESC = Sets.newHashSet("price desc","price asc");
     }

    public interface  SaleStatus{
         int NOT_SALE = 0; //商品下架状态
         int SALE = 1;  //商品上架状态
    }

    public interface  Check{
         int Unselected = 0;
         int selected = 1;
    }

    public enum OrderStatusEnum{
         CANCELED(0,"用户已取消"),
         NOT_PAID(10,"未付款"),
         PAID(20,"已付款"),
         DELIVERED(30,"已发货"),
         FINISHED(40,"交易完成");

         // 不能添加Final关键字会报错
         private  String value;
         private  int code;

         OrderStatusEnum(int code,String value){
             this.value = value;
             this.code = code;
        }

        // 调用这个对象来对传进来的
        public static OrderStatusEnum codeOf(int code){
             for (OrderStatusEnum orderStatusEnum :values()){
                 if (orderStatusEnum.getCode() == code){
                     return orderStatusEnum;
                 }
             }
             throw new ImoocMallException(ImoocMallExceptionEnum.NOT_ENUM);
        }

        public String getValue(){
             return value;
        }
        public void setValue(String value) {
            this.value = value;
        }

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }

    }
}